package com.aaa.project.service.impl;


import com.aaa.entity.OCart;
import com.aaa.entity.OOrder;
import com.aaa.entity.UUserInfo;
import com.aaa.project.mapper.OCartMapper;
import com.aaa.project.mapper.UUserInfoMapper;
import com.aaa.project.service.IOCartService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author zhangxuhui
 * @since 2023-02-01
 */
@Service
public class OCartServiceImpl extends ServiceImpl<OCartMapper, OCart> implements IOCartService {

    @Resource
    private OCartMapper oCartMapper;
    @Resource
    private UUserInfoMapper uUserInfoMapper;


    @Override
    public PageInfo getAll(Principal principal, Integer curr, Integer pageSize) {
        String name = principal.getName();
        // 根据当前的人的名字用户的id
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("telephone",name);
        UUserInfo uUserInfo=uUserInfoMapper.selectOne(queryWrapper);
        PageHelper.startPage(curr, pageSize);
        List<OCart> list=oCartMapper.getAll(uUserInfo.getId());
        System.out.println("list = " + list);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<OOrder> getOrderByCode(String code) {
        return oCartMapper.getOrderByCode(code);
    }

}
